// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import iView from 'iview';
import 'iview/dist/styles/iview.css'; 
import axios from 'axios'
import vuex_store from './js/vuex-store'
import Store from './store'
Vue.config.productionTip = false
Vue.use(iView);

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router ,
  template: '<App/>',
  components: { App },
  render: h => h(App)
})
// global.baseURL = "//api.leson-medical.com/api/"
global.baseURL = "//api.leson-medical.com/api/h5api/"
router.beforeEach((to, from, next) => {


    //如果没有用户信息,直接回到登陆页面
    if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
        
        if (window.localStorage.getItem("userToken")!=""&&window.localStorage.getItem("userToken")) {  // 通过vuex state获取当前的token是否存在
           
            

            next();
        }
        else {
            next({
                path: '/Login',
                query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
            })
        }

    }
    else {
        next();
    }
})
Date.prototype.format = function(format)
{
	 var o = {
	 "M+" : this.getMonth()+1, //month
	 "d+" : this.getDate(),    //day
	 "h+" : this.getHours(),   //hour
	 "m+" : this.getMinutes(), //minute
	 "s+" : this.getSeconds(), //second
	 "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
	 "S" : this.getMilliseconds() //millisecond
	 }
	 if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
	 (this.getFullYear()+"").substr(4 - RegExp.$1.length));
	 for(var k in o)if(new RegExp("("+ k +")").test(format))
	 format = format.replace(RegExp.$1,
	 RegExp.$1.length==1 ? o[k] :
	 ("00"+ o[k]).substr((""+ o[k]).length));
	 return format;
}



